package com.hskn.hss.module.caseset.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.controller.BaseController;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.caseset.service.ICasesetService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Slf4j
@RestController
@RequestMapping("/hss/caseset")
public class CasesetController extends BaseController {

    @Autowired
    ICasesetService casesetService;
    //    //@SysLog(businessType = BusinessType.UPDATE, idKey = "caseId", bean = Caseset.class, beanMapper = CasesMapper.class, names = "caseNo")
    @RequestMapping(value = "updateBatch", method = RequestMethod.POST)
    public AjaxResult<Object> updateBatch(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            casesetService.mUpdateBatch(params);
            return AjaxResult.success("修改成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
    @PostMapping("saveOrUpdateBatchCasesetIssue")
    public AjaxResult saveOrUpdateBatchCasesetIssue(HttpServletRequest request) {
        try {
            JSONArray params = JSONArray.parseArray(Tools.getBody(request));
            return toAjax(casesetService.saveOrUpdateBatchCasesetIssue(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail();
        }
    }

    @PostMapping("saveOrUpdateBatchCasesetIssueSource")
    public AjaxResult saveOrUpdateBatchCasesetIssueSource(HttpServletRequest request) {
        try {
            JSONArray params = JSONArray.parseArray(Tools.getBody(request));
            return toAjax(casesetService.saveOrUpdateBatchCasesetIssueSource(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail();
        }
    }
    @PostMapping("saveOrUpdateBatchCasesetLevel")
    public AjaxResult saveOrUpdateBatchCasesetLevel(HttpServletRequest request) {
        try {
            JSONArray params = JSONArray.parseArray(Tools.getBody(request));
            return toAjax(casesetService.saveOrUpdateBatchCasesetLevel(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail();
        }
    }
    @PostMapping("casesetSysUpdateById")
    public AjaxResult casesetSysUpdateById(HttpServletRequest request) {
        try {
            JSONObject params = JSONObject.parseObject(Tools.getBody(request));
            return toAjax(casesetService.casesetSysUpdateById(params));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail();
        }
    }

}

